package middleware

import (
	"github.com/gin-gonic/gin"
	"net/http"
	. "xm_shop/models"
)

// 用户中间件
func InitUserAuthMiddleware(context *gin.Context) {
	// 判断用户有没有登录
	var user User
	isLogin := Cookie.Get(context, "userInfo", &user)
	if !isLogin || user.ID == 0 {
		context.String(http.StatusBadRequest, "用户未登录")
		context.Abort() // 中断
	}
}
